package org.wx.herostory.services.util;

import org.wx.herostory.model.User;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @description: 用户管理中心
 * @author: wangxun
 * @createDate: 2021/3/1
 * @version: 1.0
 */
public final class UserManager {
   static private final Map<Integer, User> _userMap= new ConcurrentHashMap<>();

   private UserManager(){}

    /**
     * 添加用户
     * @param user
     */
   static public void addUser(User user){
       if(user != null)
           _userMap.putIfAbsent(user.getUserId(),user);
   }

    /**
     * 根据userId 删除用户
     * @param userId
     */
   static public void removeByUserId(int userId){
       _userMap.remove(userId);
   }

    /**
     * 获取用户列表
     * @return
     */
   static public Collection<User> listUsers(){
       return _userMap.values();
   }

    /**
     * 根据UserId 获取用户
     * @param userId
     * @return
     */
    static public User getUserById(Integer userId){
       return _userMap.get(userId);
    }
}
